import { fileURLToPath, URL } from "node:url";
import legacy from "@vitejs/plugin-legacy";

import { defineConfig, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";

// https://vitejs.dev/config/
export default defineConfig(({command, mode})=>{
  const env = loadEnv(mode, process.cwd(), '')
  return {
    base: env.NODE_ENV === 'production' ? "./" : '/',
    plugins: [
      legacy({
        targets: ["defaults", "not IE 11"],
      }),
      vue(),
    ],
    resolve: {
      alias: {
        "@": fileURLToPath(new URL("./src", import.meta.url)),
      },
    },
    css: {
      preprocessorOptions: {
        scss: {
          additionalData: "@import './src/style/vars.scss';",
        },
      },
    },
    server: {
      host: true,
      port: 8080,
    },
  }
});
